﻿using STMS.DbUtility;
using STMS.Models.DModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace STMS.DAL
{
    #region
    /*
    54 仓库分区删除方法封装
删除：逻辑删除-判断区是加了产品
    有，不能删除IsRegionAddProducts(regionld)
    无：可以删除DeleteRegion(regionld)(update IsDeleted=1，包括修对应仓库的分数
1)-事务
    恢复  RecoverSRegion(regionld)---updateIsDeleted=包括修改对应库的分数+1)
    移除  真删除RemoveRegion(regionld)-delete、修改对应仓库的分区数-1
方法归纳：分数删除：DeletestoreRegion(int regionld, int delTypeint IsDeleted）
    IsDeleted 0恢复 RegionCount-1 1删除 2真删除 RegionCount-1
    */
    #endregion
    public class StoreRegionDAL:BaseDAL<StoreRegionInfo>
    {
        /// <summary>
        /// 仓库分区的删除处理（真假删除、恢复处理）
        /// </summary>
        /// <param name="regionId"></param>
        /// <param name="storeId"></param>
        /// <param name="delType"></param>
        /// <param name="isDelted"></param>
        /// <returns></returns>
        public bool DeleteStoreRegion(int regionId,int storeId, int delType,int isDelted)
        {
            string strWhere = $"SRegionId={regionId}";
            string sqlDel = "";
            if (delType==1)
                 sqlDel = CreateSql.CreateDeleteSql<StoreRegionInfo>(strWhere);
            else
            {
                sqlDel=CreateSql.CreateLogicDeleteSql<StoreRegionInfo>(strWhere,isDelted);
            }
            //修改分区数的sql
            string flag = "+";
            if (isDelted>=1)// 0 1 2
                flag = "-";
            string sqlUpdate = $"update StoreInfos set RegionCount{flag}1 where StoreId";
            List<string> sqlList = new List<string>();
            sqlList.Add(sqlDel); 
            sqlList.Add(sqlUpdate);
          return  SqlHelper.ExecuteTrans(sqlList);
        }
    }
}
